#  Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995
# 	The Regents of the University of California.  All rights reserved.
#
#  Redistribution and use in source and binary forms, with or without
#  modification, are permitted provided that: (1) source code distributions
#  retain the above copyright notice and this paragraph in its entirety, (2)
#  distributions including binary code include the above copyright notice and
#  this paragraph in its entirety in the documentation or other materials
#  provided with the distribution, and (3) all advertising materials mentioning
#  features or use of this software display the following acknowledgement:
#  ``This product includes software developed by the University of California,
#  Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
#  the University nor the names of its contributors may be used to endorse
#  or promote products derived from this software without specific prior
#  written permission.
#  THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# @(#) $Header: Makefile.in,v 1.152+ 94/06/16 20:55:40 leres Exp $ (LBL)

#
# You might want to edit these path names.
#

# Full pathname of where to install the binaries
BINDEST = /usr/local/sbin/tcpdump
# Full pathname of where to install the manual entries
MANDEST = /usr/local/man/man1/tcpdump.1

#
# You shouldn't need to edit anything below here.
#

# Possible Options:
#  -DCSLIP	include support for kernel slip interface
#  -DPPP	include support for point to point protocol
#  -DIBMRTPC	enable the MERIT additions to the Stanford Enetfilter
#  -DDECNETLIB	use the optional DECnet library under Ultrix and others
#  -DNOVFPRINTF	simulate vfprintf() on systems that don't have it
#
# CSLIP and PPP work only under BPF.
#

#have-cslip#CSLIP_DEFINES = -DCSLIP
#have-dnet#DNET_DEFINES = -DDECNETLIB
#have-ethers#ETHERS_DEFINES = -DETHER_SERVICE
#have-aix2#OS_DEFINES = -DSVR4
#have-irix5#OS_DEFINES = -DSVR4 -D_BSD_SIGNALS
#have-sunos3#OS_DEFINES = -DSUNOS3
#have-sunos5#OS_DEFINES = -DSOLARIS -DSVR4
#have-linux#OS_DEFINES = -DPPP -DCSLIP

# DEFINES per machine vs. os
#have-rt-bsd#MD_OS_DEFINES = -DNOVFPRINTF

# cc (i.e. not gcc) dependent flags per machine vs. os
#have-alpha-osf1v1#MD_OS_CFLAGS = -g3
#have-mips-irix4#MD_OS_CFLAGS = -xansi -D__STDC__ -Dinline=
#have-mips-irix5#MD_OS_CFLAGS = -xansi -D__STDC__ -Dinline=
#have-rt-bsd#MD_OS_CFLAGS = -U__STDC__

LOCAL_INCLUDES = -I/usr/local/include
#have-gcc#LOCAL_INCLUDES =

CCOPT = -O
INCLUDES = -Ilibpcap $(LOCAL_INCLUDES)
#have-linux#INCLUDES = -Ilibpcap -Ilinux-include $(LOCAL_INCLUDES)
OPTIONAL_DEFINES = $(ETHERS_DEFINES) $(DNET_DEFINES) $(OS_DEFINES)
DEFINES = $(CSLIP_DEFINES) -DPPP -DHAVE_FDDI \
    $(MD_OS_DEFINES) $(OPTIONAL_DEFINES)

# gcc flags
GCC_PROTO_FLAGS = -Wmissing-prototypes -Wstrict-prototypes
#have-gcc1#GCC_PROTO_FLAGS =

# Compiler dependent flags
CC_FLAGS = $(MD_OS_CFLAGS)
#have-gcc#CC_FLAGS = -g -Wall $(GCC_PROTO_FLAGS)

# Standard CFLAGS
CFLAGS = $(CCOPT) $(CC_FLAGS) $(DEFINES) $(INCLUDES)

# Standard C compiler
CC = cc
#have-gcc#CC = gcc

# Optional libraries as available
#have-dnet#DNET_LIBS = -ldnet

# Optional libraries per machine vs. os
#have-sun4-sunos5#MD_OS_LIBS = -lsocket -lnsl
#have-alpha-osf1v1#MD_OS_LIBS = /usr/examples/packetfilter/pfopen.c
#have-alpha-osf1v2#MD_OS_LIBS =

LOCAL_LIBS = -L/usr/local/lib
#have-gcc#LOCAL_LIBS =

# Standard LIBS
LIBS = -Llibpcap $(LOCAL_LIBS) $(DNET_LIBS) $(MD_OS_LIBS) -lpcap

# The installed binary is owned by this group.
GROUP = staff
#have-sunos5#GROUP = sys
#have-alpha-osf1v1#GROUP = system
#have-alpha-osf1v2#GROUP = system
#have-alpha-osf1v3#GROUP = system
#have-bpf#GROUP = bpf
#have-linux#GROUP = 0

MAKE = make

# Explicitly define compiliation rule since SunOS 4's make doesn't like gcc.
# Also, gcc does not remove the .o before forking 'as', which can be a
# problem if you don't own the file but can write to the directory.
.c.o:
	rm -f $@; $(CC) $(CFLAGS) -c $*.c

CSRC =	tcpdump.c addrtoname.c \
	print-ether.c print-ip.c print-arp.c print-tcp.c print-udp.c \
	print-atalk.c print-domain.c print-tftp.c print-bootp.c print-nfs.c \
	print-icmp.c print-sl.c print-ppp.c print-rip.c \
	print-snmp.c print-ntp.c print-null.c print-egp.c print-ospf.c \
	print-fddi.c print-llc.c print-sunrpc.c \
	print-wb.c print-decnet.c print-isoclns.c print-ipx.c \
	util.c bpf_dump.c parsenfsfh.c
GEN =	version.c

SRC =	$(CSRC) $(GEN)
ALLSRC = \
	$(CSRC)

OBJ =	$(SRC:.c=.o)
# Some makes can't handle the above substitution
#have-broken-make#OBJ = tcpdump.o addrtoname.o \
#have-broken-make#	print-ether.o print-ip.o print-arp.o print-tcp.o \
#have-broken-make#	print-udp.o print-atalk.o print-domain.o print-tftp.o \
#have-broken-make#	print-bootp.o print-nfs.o print-icmp.o print-sl.o \
#have-broken-make#	print-ppp.o print-rip.o print-snmp.o print-ntp.o \
#have-broken-make#	print-null.o print-egp.o print-ospf.o print-fddi.o \
#have-broken-make#	print-llc.o print-sunrpc.o print-wb.o print-decnet.o \
#have-broken-make#	print-isoclns.o print-ipx.o util.o \
#have-broken-make#	bpf_dump.o parsenfsfh.o \
#have-broken-make#	version.o

HDR =	addrtoname.h appletalk.h bootp.h decnet.h \
	ethertype.h extract.h fddi.h interface.h llc.h mib.h \
	nfsv2.h ntp.h ospf.h nfsfh.h ipx.h
MDHDR =	md-hp300.h md-sun3.h md-sun4.h md-mips.h md-vax.h md-rt.h md-alpha.h \
	md-i386.h
OSHDR =	os-bsd.h os-sunos3.h os-sunos4.h os-sunos5.h os-ultrix4.h os-osf1v1.h \
	os-osf1v2.h os-osf1v3.h os-irix4.h os-irix5.h

TAGHDR = \
	/usr/include/netinet/in.h \
	/usr/include/netinet/udp.h \
	/usr/include/netinet/tcp.h \
	/usr/include/arpa/tftp.h \
	/usr/include/netinet/if_ether.h

TAGFILES = \
	$(SRC) $(HDR) md.h os.h $(TAGHDR)

AWKS =	atime.awk packetdat.awk send-ack.awk stime.awk

TARFILES = \
	README CHANGES INSTALL VERSION Makefile.in tcpdump.1 makemib mkdep \
	$(ALLSRC) $(HDR) $(MDHDR) $(OSHDR) \
	$(AWKS) configure

tcpdump: $(OBJ)
	$(CC) $(CFLAGS) -o $@ $(OBJ) $(LIBS)

version.o: version.c
version.c: VERSION
	rm -f version.c; sed -e 's/.*/char version[] = "&";/' VERSION > $@

install: force
	rm -f $(DESTDIR)$(BINDEST) $(DESTDIR)$(MANDEST)
	cp tcpdump $(DESTDIR)$(BINDEST)
	chmod 550 $(DESTDIR)$(BINDEST)
	chgrp $(GROUP) $(DESTDIR)$(BINDEST)
	cp tcpdump.1 $(DESTDIR)$(MANDEST)

lint:	$(GEN) force
	lint -hbxn $(SRC) | \
	    grep -v 'struct/union .* never defined' | \
	    grep -v 'possible pointer alignment problem'

clean:
	rm -f $(OBJ) tcpdump $(GEN)

realclean:
	rm -f $(OBJ) tcpdump $(GEN) md.h os.h libpcap Makefile tags

tags:	$(TAGFILES)
	ctags -wtd $(TAGFILES)

tar:	$(GEN) force
	@cwd=`pwd` ; dir=`basename $$cwd` ; name=tcpdump-`cat VERSION` ; \
	    list="" ; tar="tar cFFf" ; \
	    for i in $(TARFILES) ; do list="$$list $$name/$$i" ; done; \
	    echo \
	    "rm -f ../$$name; ln -s $$dir ../$$name" ; \
	     rm -f ../$$name; ln -s $$dir ../$$name ; \
	    echo \
	    "(cd .. ; $$tar - [lots of files]) | compress > /tmp/$$name.tar.Z" ; \
	     (cd .. ; $$tar - $$list) | compress > /tmp/$$name.tar.Z ; \
	    echo \
	    "rm -f ../$$name" ; \
	     rm -f ../$$name

force:	/tmp
depend:	$(GEN) force
	./mkdep -c $(CC) $(DEFINES) $(INCLUDES) $(SRC)
